package ListView_Adapter;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.ArrayList;

import barcode.code.nhat.iuhbarcode.R;

/**
 * Created by Nhat on 7/10/2014.
 */
public class StudentList_Adapter extends BaseAdapter {

    private Context context;
    private ArrayList<Student_Detail> student_details;

    private StudentList_Adapter() {
    }

    public StudentList_Adapter(Context context, ArrayList<Student_Detail> student_details) {
        this.context = context;
        this.student_details = student_details;
    }


    @Override
    public int getCount() {
        return student_details.size();
    }

    @Override
    public Object getItem(int position) {
        return student_details.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View v, ViewGroup parent) {
        if (v == null) {
            LayoutInflater mInflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
            v = mInflater.inflate(R.layout.list_student, null);
        }

        TextView t1,t2,t3,t4;
        t1 = (TextView) v.findViewById(R.id.row_id);
        t2 = (TextView) v.findViewById(R.id.row_fname);
        t3 = (TextView) v.findViewById(R.id.row_lname);
        t4 = (TextView) v.findViewById(R.id.row_class);

        t1.setText(String.valueOf(student_details.get(position).getId_s()));
        t2.setText(student_details.get(position).getFname());
        t3.setText(student_details.get(position).getLname());
        t4.setText(student_details.get(position).getC_name());
        return v;
    }

}
